package com.onesports.intelligent.k12.polarlight.service.sys;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.onesports.framework.kit.common.util.BeanUtils;
import com.onesports.intelligent.k12.polarlight.domain.entity.sys.BizAttachmentFile;
import com.onesports.intelligent.k12.polarlight.mapper.sys.BizAttachmentFileMapper;
import com.onesports.intelligent.k12.polarlight.util.RedisUtils;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 附件表
 *
 * @author
 * @since 1.0.0 2022-07-21
 */
@Service
@RequiredArgsConstructor
public class BizAttachmentFileService extends ServiceImpl<BizAttachmentFileMapper, BizAttachmentFile> {

    private final RedisUtils redisUtils;

    private final String FILE_CACHE_KEY = "FILE_CACHE:";

    public void saveForCache(List<BizAttachmentFile> list){
        list.forEach(item->{
            redisUtils.set(FILE_CACHE_KEY+item.getFileName(),item,3600);
        });
    }

    public BizAttachmentFile getForCache(String fileName){
        if(StringUtils.isNotBlank(fileName)){
            return redisUtils.get(FILE_CACHE_KEY+fileName,BizAttachmentFile.class);
        }
        return null;
    }



}
